package gdonly.top.signin.business;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import gdonly.top.signin.R;
import gdonly.top.signin.entity.User;
import gdonly.top.signin.widgets.SubRecyclerViewAdapter;

/**
 * Created by zhuzhuxia on 2017/4/29.
 */
public class ShowSignResultActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_result);
        initRecyclerViews();
    }
    private void initRecyclerViews(){
        RecyclerView recyclerView= (RecyclerView) findViewById(R.id.recyle_schedule);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        List<User> users = ((Application)getApplication()).getTruntUsers();
        ArrayList<HashMap<String, Object>> datas = new ArrayList<>();
        Bundle bundle = getIntent().getExtras();
        String courseName = bundle.getString("course_name");
        String date = bundle.getString("date");

        if(users.size() == 0){

            ImageView imageView = (ImageView) findViewById(R.id.show_success_img1);
            TextView showText = (TextView) findViewById(R.id.show_success_text1);

            showText.setVisibility(View.VISIBLE);
            imageView.setVisibility(View.VISIBLE);
        }
        else {
            for (User user : users) {
                HashMap<String, Object> map = new HashMap();
                map.put("stu_name", user.getName());
                map.put("stu_id", user.getId());
                map.put("course_name", courseName);

                map.put("date", date);
                map.put("state",user.isSign());

                datas.add(map);
            }


            recyclerView.setAdapter(new SubRecyclerViewAdapter(datas, ShowSignResultActivity.this));
        }
    }
}
